//
//  MercPermanceDetailTotalVM.swift
//  kxf
//
//  Created by LNS2 on 2024/4/9.
//

import Foundation
import UIKit

class MercPermanceDetailTotalVM: UIView {
    
    let selfHeight = kFitWidth(113)
    
    override init(frame:CGRect){
        super.init(frame: CGRect.init(x: 0, y: 0, width: SCREEN_WIDHT, height: selfHeight))
        self.backgroundColor = .clear
        self.isUserInteractionEnabled = true
        self.layer.cornerRadius = kFitWidth(8)
        self.clipsToBounds = true
        
        
        initUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var whiteView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(10)
        vi.clipsToBounds = true
        vi.backgroundColor = .white
        vi.isUserInteractionEnabled = true
        
        return vi
    }()
    lazy var avatarImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "performance_cell_avatar")
        
        return img
    }()
    lazy var nameLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .medium)
        
        return lab
    }()
    lazy var lineView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LIGHT_GREY
        
        return vi
    }()
    lazy var tradeNumLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var tradeNumLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.text = "交易金额（元）"
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rebateLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .medium)
        lab.adjustsFontSizeToFitWidth = true
        lab.textAlignment = .center
        
        return lab
    }()
    lazy var rebateLab : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 12, weight: .regular)
        lab.text = "贡献收益（元）"
        lab.textAlignment = .center
        
        return lab
    }()
}

extension MercPermanceDetailTotalVM{
    func updateUI(dict:NSDictionary) {
        tradeNumLabel.text = "\(dict["totalAmount"]as? Double ?? 0.00)"
        rebateLabel.text = "\(dict["totalProfit"]as? Double ?? 0.00)"
    }
}
extension MercPermanceDetailTotalVM{
    func initUI() {
        addSubview(whiteView)
        whiteView.addSubview(avatarImgView)
        whiteView.addSubview(nameLabel)
        
        whiteView.addSubview(lineView)
        whiteView.addSubview(tradeNumLabel)
        whiteView.addSubview(tradeNumLab)
        whiteView.addSubview(rebateLabel)
        whiteView.addSubview(rebateLab)
        
        setConstrait()
    }
    func setConstrait() {
        whiteView.snp.makeConstraints { make in
            make.left.top.width.equalToSuperview()
            make.height.equalTo(kFitWidth(103))
        }
        avatarImgView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(18))
            make.top.equalTo(kFitWidth(12))
            make.width.height.equalTo(kFitWidth(22))
        }
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(avatarImgView.snp.right).offset(kFitWidth(3))
            make.centerY.lessThanOrEqualTo(avatarImgView)
            make.right.equalTo(kFitWidth(-75))
        }
        lineView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(124))
            make.top.equalTo(kFitWidth(34))
            make.width.equalTo(kFitWidth(0.4))
            make.height.equalTo(kFitWidth(17))
        }
        tradeNumLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(8))
            make.width.equalTo(kFitWidth(95))
            make.top.equalTo(kFitWidth(47))
            make.height.equalTo(kFitWidth(28))
        }
        tradeNumLab.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualTo(tradeNumLabel)
            make.top.equalTo(tradeNumLabel.snp.bottom).offset(kFitWidth(2))
        }
        rebateLabel.snp.makeConstraints { make in
            make.left.equalTo(lineView.snp.right).offset(kFitWidth(8))
            make.centerY.lessThanOrEqualTo(tradeNumLabel)
            make.width.equalTo(tradeNumLabel)
        }
        rebateLab.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualTo(rebateLabel)
            make.centerY.lessThanOrEqualTo(tradeNumLab)
        }
    }
}
